<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>测试图片上传</title>

    <script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <link href="layui/css/layui.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<div class="layui-input-inline" style="margin-left: 100px;margin-top: 100px;">
    <img class="uploadImg" width="87px;" height="87px;" style="cursor: pointer"
         src="img/addimg.png"/>
</div>

</body>
<script>
    layui.use(['layer', 'upload'], function () {
        var $ = layui.$
            , layer = layui.layer
            , upload = layui.upload

        // var upload_url = 'http://127.0.0.1:8072/fms/index/upload_file';
        var upload_url = '/index/upload_file';
        var upload_project_name = 'fms';

        upload.render({
            elem: '.uploadImg'
            , url: upload_url
            , data: {projectName: upload_project_name, moduleName: 'user'}
            , accept: 'file'
            , ext: 'jpg|png'
            , done: function (res) {
                if (res.success) {
                    var src = res.result.src;
                    console.log(src);
                    $(".uploadImg").attr("src", src);
                    layer.msg("图片上传成功");
                } else {
                    layer.alert("图片上传失败! \n " + res.message);
                }
            }
            , error: function () {
                layer.alert("图片上传失败!");
            }
        });

    });
</script>
</html>